package com.ktjiaoyu.server.controller;

import com.ktjiaoyu.server.domain.dto.LoginDto;
import com.ktjiaoyu.server.domain.pojo.Admin;
import com.ktjiaoyu.server.service.AdminService;
import com.ktjiaoyu.server.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(tags = "认证相关接口")
@RestController
public class LoginController {

    @Autowired
    private AdminService adminService;

    @ApiOperation(value = "登录接口",notes = "详细说明。。。。")
    @PostMapping("/doLogin")
    @ResponseBody
    public ResponseResult doLogin(@RequestBody LoginDto loginDto){
        //检查验证码
        if (!adminService.checkCaptcha(loginDto.getUuid(),loginDto.getCaptcha())){
            return  ResponseResult.error("验证码错误");
        }

        String token = adminService.login(loginDto);
        ResponseResult responseResult = ResponseResult.success("登陆成功");
        responseResult.put("token",token);
        return responseResult;
    }
    @ApiOperation(value = "登出接口",notes = "详细说明。。。")
    @PostMapping("/doLogout")
    public ResponseResult doLogout(){
        adminService.logout();
        return ResponseResult.success();
    }




    @GetMapping("/hello")
    public  String hello(){
        return "cgvhj;'";
    }
}
